package com.csi.bumblebee.service.impl;

import com.csi.bumblebee.domain.dictionary.School;
import com.csi.bumblebee.mapper.SchoolMapper;
import com.csi.bumblebee.service.SchoolService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * @author 孙伟俊
 */
@Service
public class SchoolServiceImpl implements SchoolService {

    @Autowired
    private SchoolMapper schoolMapper;

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public School findNameById(String id) {
        School school = (School) redisTemplate.opsForValue().get(id);
        if (school != null) {
            return school;
        }else {
            school = schoolMapper.findNameById(id);
            redisTemplate.opsForValue().set(id, school);
            return school;
        }
    }

    @Override
    public List<School> list() {
        return schoolMapper.listAllSchool();
    }

    @Override
    public int insertSelective(School school) {
        int result = schoolMapper.insertSelective(school);
        if (result > 0) {
            List<School> list = schoolMapper.list();
            redisTemplate.opsForValue().set("schools", list);
        }
        return result;

    }

    @Override
    public int updateByPrimaryKeySelective(School school) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(String id) {
        return 0;
    }
}
